Skip to content

fix(sync): stop provider_event_identity collisions on series instance edits - #2748

Merged
cursor[bot] merged 2 commits into
mainfrom
cursor/fix-provider-event-identity-dup-4d2f
Aug 10, 2026
Merged

fix(sync): stop provider_event_identity collisions on series instance edits#2748
cursor[bot] merged 2 commits into
mainfrom
cursor/fix-provider-event-identity-dup-4d2f

Conversation

@tyler-dane

Copy link
Copy Markdown
Contributor

Summary

Fixes the PostHog errors where scope-this command execution (and the staleCommandRetry sweep retrying those stuck commands) threw Mongo E11000 on compass_sync.events index provider_event_identity.

Root cause: Google import wrote series exceptions via upsertByProviderIdentity with offset-form recurrenceIds (2026-08-10T13:00:00-06:00), while commands wrote via upsertException keyed on the canonical UTC form (2026-08-10T19:00:00.000Z). Same instant, different strings → series filter miss → insert collided with the imported providerEventId (masterId_20260810T190000Z). The failed command stayed nonterminal, so staleCommandRetry looped the same error.

Fix:

  1. Canonicalize Google instance/cancellation recurrenceIds to Date#toISOString() (matching projection and command paths).
  2. Harden upsertException to converge on an existing provider-identity document (and drop a series-keyed duplicate when both exist), including E11000 race recovery.

Issues

Test plan

  • bun test packages/sync/src/providers/google/google-event.normalizer.test.ts
  • bun test:sync -- packages/sync/src/storage/repositories/event.repository.db.test.ts (includes new dual-key / format-mismatch regressions)
  • Broader bun test:sync + bun lint after PR open
Open in Web Open in Cursor 

cursoragent and others added 2 commits August 10, 2026 21:16
Google imports stored instance recurrenceIds as offset ISO strings while
commands use Date#toISOString(), so upsertException missed the imported
row and collided provider_event_identity. Canonicalize import recurrenceIds
and make upsertException adopt the existing provider-identity document.

Co-authored-by: Tyler Dane <tyler-dane@users.noreply.github.com>
Canonical UTC recurrenceIds made import collide series_exception_identity
with null-provider command tombstones. Reconcile before provider-identity
upserts so import adopts or drops the series-keyed row first.

Co-authored-by: Tyler Dane <tyler-dane@users.noreply.github.com>
@cursor
cursor Bot marked this pull request as ready for review August 10, 2026 21:35
@cursor
cursor Bot merged commit aa7ca26 into main Aug 10, 2026
20 checks passed
@cursor
cursor Bot deleted the cursor/fix-provider-event-identity-dup-4d2f branch August 10, 2026 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants